<?php
class DetalleordencomprasController extends AppController {

	var $name = 'Detalleordencompras';
	var $components = array('RequestHandler');
	
	function index($ordencompra_id){
		$this->layout="ajax";
					
		if($this->JQGridPaginate->isGrid){
			$fields = array('Detalleordencompra.id',
							'"Articulo"."codigo" AS "Detalleordencompra__articulocodigo"',
							'"Articulo"."descripcion" AS "Detalleordencompra__articulodescripcion"',
							'"Articulo"."presentacion" AS "Detalleordencompra__articulopresentacion"',
							'Detalleordencompra.cantidad',
							'Detalleordencompra.prc_total',
							'Detalleordencompra.cantidad_nt_ing',
							'Detalleordencompra.observacion');
			
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			$this->autoRender = false;
			
			echo $this->JQGridPaginate->paginate("Detalleordencompra");
			
		}elseif ($this->RequestHandler->isPost()){	
			$this->autoRender = false;
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
				$this->Detalleordencompra->create();				 
			}elseif ($oper == "edit"){
				$this->data['Detalleordencompra']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Detalleordencompra']['id'] = $this->params['form']['id'];
				$this->data['Detalleordencompra']['estado_id'] = 2;				
			}
			
			$this->Detalleordencompra->save($this->data);			
		}		
	}	
}